package com.hl.controller.frontjuan;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hl.domain.ShopJuan;
import com.hl.service.ILingJuanZhongXinService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 领券中心Controller
 * 
 * @author ruoyi
 * @date 2025-01-27
 */
@RestController
@RequestMapping("/lingJuanZhongXin")
public class LingJuanZhongXinController extends BaseController
{
    @Autowired
    private ILingJuanZhongXinService lingJuanZhongXinService;
    /**
     * 前端查询领券中心列表
     */
//    @RequiresPermissions("lingJuanZhongXin:lingJuanZhongXin:list")
    @GetMapping("/list")
    public TableDataInfo list(ShopJuan shopJuan)
    {
        startPage();
        List<ShopJuan> list = lingJuanZhongXinService.selectShopJuanList(shopJuan);
        return getDataTable(list);
    }


    /**
     * 查询领券中心列表
     */
    @RequiresPermissions("lingJuanZhongXin:lingJuanZhongXin:list")
    @GetMapping("/list1")
    public TableDataInfo list1(ShopJuan shopJuan)
    {
        startPage();
        List<ShopJuan> list = lingJuanZhongXinService.selectShopJuanList(shopJuan);
        return getDataTable(list);
    }
    /**
     * 导出领券中心列表
     */
    @RequiresPermissions("lingJuanZhongXin:lingJuanZhongXin:export")
    @Log(title = "领券中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopJuan shopJuan)
    {
        List<ShopJuan> list = lingJuanZhongXinService.selectShopJuanList(shopJuan);
        ExcelUtil<ShopJuan> util = new ExcelUtil<ShopJuan>(ShopJuan.class);
        util.exportExcel(response, list, "领券中心数据");
    }

    /**
     * 获取领券中心详细信息
     */
    @RequiresPermissions("lingJuanZhongXin:lingJuanZhongXin:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(lingJuanZhongXinService.selectShopJuanById(id));
    }

    /**
     * 根据店铺ID查询领券中心
     */
    @RequiresPermissions("lingJuanZhongXin:lingJuanZhongXin:query")
    @GetMapping(value = "/shop/{shopId}")
    public AjaxResult getInfoByShopId(@PathVariable("shopId") Integer shopId)
    {
        return success(lingJuanZhongXinService.selectShopJuanByShopId(shopId));
    }

    /**
     * 根据优惠券ID查询领券中心
     */
//    @RequiresPermissions("lingJuanZhongXin:lingJuanZhongXin:query")
    @GetMapping(value = "/coupon/{couponId}")
    public AjaxResult getInfoByCouponId(@PathVariable("couponId") Integer couponId)
    {
        return success(lingJuanZhongXinService.selectShopJuanByCouponId(couponId));
    }

    /**
     * 统计店铺优惠券数量
     */
    @RequiresPermissions("lingJuanZhongXin:lingJuanZhongXin:query")
    @GetMapping(value = "/count/shop/{shopId}")
    public AjaxResult countByShopId(@PathVariable("shopId") Integer shopId)
    {
        return success(lingJuanZhongXinService.countShopJuanByShopId(shopId));
    }

    /**
     * 统计优惠券被使用的店铺数量
     */
    @RequiresPermissions("lingJuanZhongXin:lingJuanZhongXin:query")
    @GetMapping(value = "/count/coupon/{couponId}")
    public AjaxResult countByCouponId(@PathVariable("couponId") Integer couponId)
    {
        return success(lingJuanZhongXinService.countShopJuanByCouponId(couponId));
    }

    /**
     * 新增领券中心
     */
    @RequiresPermissions("lingJuanZhongXin:lingJuanZhongXin:add")
    @Log(title = "领券中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopJuan shopJuan)
    {
        return toAjax(lingJuanZhongXinService.insertShopJuan(shopJuan));
    }

    /**
     * 修改领券中心
     */
    @RequiresPermissions("lingJuanZhongXin:lingJuanZhongXin:edit")
    @Log(title = "领券中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopJuan shopJuan)
    {
        return toAjax(lingJuanZhongXinService.updateShopJuan(shopJuan));
    }

    /**
     * 删除领券中心
     */
    @RequiresPermissions("lingJuanZhongXin:lingJuanZhongXin:remove")
    @Log(title = "领券中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(lingJuanZhongXinService.deleteShopJuanByIds(ids));
    }

    /**
     * 根据店铺ID删除领券中心
     */
    @RequiresPermissions("lingJuanZhongXin:lingJuanZhongXin:remove")
    @Log(title = "领券中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/shop/{shopId}")
    public AjaxResult removeByShopId(@PathVariable Integer shopId)
    {
        return toAjax(lingJuanZhongXinService.deleteShopJuanByShopId(shopId));
    }

    /**
     * 根据优惠券ID删除领券中心
     */
    @RequiresPermissions("lingJuanZhongXin:lingJuanZhongXin:remove")
    @Log(title = "领券中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/coupon/{couponId}")
    public AjaxResult removeByCouponId(@PathVariable Integer couponId)
    {
        return toAjax(lingJuanZhongXinService.deleteShopJuanByCouponId(couponId));
    }
} 